<template>
  <UploadExcel :on-success="handleSuccess" />
</template>

<script>
import { reqImportEmployee } from '@/api/employees'
export default {
  name: 'Import',
  computed: {
    type() {
      return this.$route.query.type
    }
  },
  methods: {
    async handleSuccess({ header, results }) {
      if (this.type === 'user') {
        const arr = []
        const userRelations = {
          '入职日期': 'timeOfEntry',
          '手机号': 'mobile',
          '姓名': 'username',
          '转正日期': 'correctionTime',
          '工号': 'workNumber'
        }
        results.forEach(item => {
          const obj = {}
          for (const key in item) {
            const enKey = userRelations[key]
            obj[enKey] = item[key]
          }
          arr.push(obj)
        })
        console.log(arr)
        await reqImportEmployee(arr)
        this.$router.back()
      }
    }
  }
}
</script>

<style>

</style>
